//
//  TimeLabel.m
//  视频播放
//
//  Created by user1 on 2018/8/2.
//  Copyright © 2018年 Beijing Youjiu Network. All rights reserved.
//

#import "TimeLabel.h"
@interface TimeLabel ()

@end
@implementation TimeLabel

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

- (void)setMinute:(NSInteger)minute{
    _minute = minute;
}

- (void)setSecond:(NSInteger)second{
    _second = second;
    self.text = [NSString stringWithFormat:@"%.2ld:%.2ld",(long)self.minute,(long)self.second];
}

- (void)timeStart{
    self.second = 00;
    self.minute = 03;
    self.text = @"03:00";
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeHeadle) userInfo:nil repeats:YES];
}
- (void)timerStop {
    [timer invalidate];
    timer = nil;
}
- (void)timeHeadle{
    self.second--;
    if (self.second==-1) {
        self.second=59;
        self.minute--;
        if (self.minute==-1) {
            self.minute=59;
        }
    }
    if (self.hour>0) {
        self.text = [NSString stringWithFormat:@"%.2ld:%.2ld:%.2ld",(long)self.hour,(long)self.minute,(long)self.second];
    }else if (self.hour==0) {
        self.text = [NSString stringWithFormat:@"%.2ld:%.2ld",(long)self.minute,(long)self.second];
    }else if (self.minute==0)
    {
        self.text = [NSString stringWithFormat:@"%.2ld",(long)self.second];
    }
    
    if (self.second==0 && self.minute==0) {
        [self timerStop];
    }
}


@end

